package com.hnucm.c201901020121.Fragment.Home;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.graphics.ColorUtils;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.hnucm.c201901020121.Activity.PublishTaskAct;
import com.hnucm.c201901020121.Activity.TaskDetailAct;
import com.hnucm.c201901020121.R;
import com.hnucm.c201901020121.Utils.Bmob.BmobTask;
import com.hnucm.c201901020121.Utils.Bmob.TaskShow;
import com.hnucm.c201901020121.Utils.Interfaces.OnRecyclerItemClickListener;
import com.hnucm.c201901020121.Utils.OtherUtils.BannerImageLoader;
import com.hnucm.c201901020121.Utils.OtherUtils.ColorInfo;
import com.hnucm.c201901020121.Utils.OtherUtils.DatabaseHelper;
import com.youth.banner.Banner;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoaderInterface;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.datatype.BmobQueryResult;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SQLQueryListener;

public class HomeFragment extends Fragment {
    RecyclerView recyclerView;
    String intentTaskId;
    View viewBg;
    Banner banner;
    private List<String> bannerList = new ArrayList<>();
    private BannerImageLoader imageLoader;
    List<String> stringList = new ArrayList<>();
    List<TaskShow> taskList = new ArrayList<>();
    MyAdapter myAdapter;
    private List<ColorInfo> colorList = new ArrayList<>();
    private OnRecyclerItemClickListener monItemClickListener;
    ImageView publish;
    private int count;
    private boolean isInit = true;
    final DatabaseHelper dbHelper = new DatabaseHelper(getContext());
    LinearLayout pointContainer;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, container, false);

        return view;
    }
    private void insertSql() {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("headimg", "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2590128318,632998727&fm=26&gp=0.jpg");
        values.put("title", "2斤苹果");
        values.put("label", "购买水果");
        values.put("amount", "10");
        values.put("type", "2");
        values.put("headimg1", "http://a1.qpic.cn/psc?/V54ETsN62Rdw772wFsNq0jEkXI4LU2rF/05RlWl8gsTOH*Z17MtCBzPyrtO7XL5k6Lsqco9PbJO5jo0PguRSlDuZG2o*EsawzRP.Xax3a0DnuQnqkgIUtDA!!/m&ek=1&kp=1&pt=0&bo=OAQ4BDgEOAQRADc!&tl=1&tm=1620190800&sce=0-12-12&rf=0-18");
        values.put("title1", "小件中通快递");
        values.put("label1", "中通");
        values.put("amount1", "2");
        values.put("img1", "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2590128318,632998727&fm=26&gp=0.jpg");
        values.put("img2", "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2590128318,632998727&fm=26&gp=0.jpg");
        values.put("img3", "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2590128318,632998727&fm=26&gp=0.jpg");
        values.put("img4", "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2590128318,632998727&fm=26&gp=0.jpg");
        long id = db.insert("tasklist", null, values);
        Log.d("myDeBug", "insert");
        db.close();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        recyclerView = getActivity().findViewById(R.id.recyclerview);
        myAdapter = new MyAdapter();
        viewBg=getActivity().findViewById(R.id.view7);
        publish = getActivity().findViewById(R.id.imageView68);
        setStatusBarColor(getActivity(), Color.parseColor("#E84830"));
        viewBg.setBackgroundColor(Color.parseColor("#E84830"));
        publish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(), PublishTaskAct.class);
                startActivity(intent);
            }
        });
        myAdapter.setRecyclerItemClickListener(new OnRecyclerItemClickListener() {
            @Override
            public void onItemClick(int Position, List<TaskShow> taskList) {
                Intent intent = new Intent(getContext(), TaskDetailAct.class);
                intent.putExtra("taskId", intentTaskId);
                startActivity(intent);
            }
        });
        stringList.clear();
        stringList.add("http://photogz.photo.store.qq.com/psc?/V13FgbWj3x2RyI/05RlWl8gsTOH*Z17MtCBzL38dQIMpiYdn8ShmfcTlrB7hszajovOcG6bK.MZRKCVpJz6MkkTubTObfR8SmxhrA!!/m&bo=dgWNAXYFjQERADc!&rf=mood_app");
        stringList.add("http://photogz.photo.store.qq.com/psc?/V13FgbWj3x2RyI/05RlWl8gsTOH*Z17MtCBzPPKeusL5Yh5Me*b9D9zIEzfwj449tGqot8n*P5fppSq.xNrIOEi6SCRnjWPBvSq9A!!/m&bo=eAWOAXgFjgERADc!&rf=mood_app");
        stringList.add("http://photogz.photo.store.qq.com/psc?/V13FgbWj3x2RyI/05RlWl8gsTOH*Z17MtCBzOW.ae376BfI9lGqS3HjDUb5oNlSXGoMgFfKuN0T.uuIfh9AR75LBj68IZwrB1zHJQ!!/m&bo=IwPZACMD2QARADc!&rf=mood_app");
        stringList.add("http://photogz.photo.store.qq.com/psc?/V13FgbWj3x2RyI/05RlWl8gsTOH*Z17MtCBzLojxvQGIuIDakj72A2tcGXUTs6ac0pqlFaMItaWj0tQTUVqg6jXn5TioYk6Lbf6YA!!/m&bo=zgWiAc4FogERADc!");
        recyclerView.setAdapter(myAdapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        getDate();
    }

    private void getDate() {
        String sql = "select * from BmobTask where recom=1 order by type,updatedAt desc";
        BmobQuery<BmobTask> query = new BmobQuery<BmobTask>();
        query.setSQL(sql);
        query.doSQLQuery(new SQLQueryListener<BmobTask>() {
            @RequiresApi(api = Build.VERSION_CODES.N)
            @Override
            public void done(BmobQueryResult<BmobTask> bmobQueryResult, BmobException e) {
                if (e == null) {
                    int num = 4, fl = 1;
                    List<BmobTask> list = (List<BmobTask>) bmobQueryResult.getResults();
                    taskList.clear();
                    for (int i = 0; i < list.size(); ++i) {
                        if (list.get(i).getType() == 1 && num != 0) {
                            TaskShow taskShow = new TaskShow();
                            taskShow.setHeadimg(list.get(i).getHeadimg());
                            taskShow.setTitle(list.get(i).getTitle());
                            taskShow.setLabel(list.get(i).getLabel());
                            taskShow.setAmount(list.get(i).getAmount());
                            taskShow.setTaskId(list.get(i).getObjectId());
                            taskShow.setHeadimg1(list.get(i + 1).getHeadimg());
                            taskShow.setTitle1(list.get(i + 1).getTitle());
                            taskShow.setLabel1(list.get(i + 1).getLabel());
                            taskShow.setAmount1(list.get(i + 1).getAmount());
                            taskShow.setTaskId1(list.get(i + 1).getObjectId());
                            taskShow.setType(2);
                            taskList.add(taskShow);
                            ++i;
                            --num;
                        }
                        else if (num == 0 && fl == 1) {
                            TaskShow taskShow = new TaskShow();
                            taskShow.setType(5);
                            taskList.add(taskShow);
                            fl = 0;
                        } else if (list.get(i).getType() == 1) {
                            TaskShow taskShow = new TaskShow();
                            taskShow.setHeadimg(list.get(i).getHeadimg());
                            taskShow.setTitle(list.get(i).getTitle());
                            taskShow.setLabel(list.get(i).getLabel());
                            taskShow.setAmount(list.get(i).getAmount());
                            taskShow.setTaskId(list.get(i).getObjectId());
                            taskShow.setTaskTime(list.get(i).getTaskTime());
                            taskShow.setType(1);
                            taskShow.setTime(list.get(i).getCreatedAt().substring(5, 16));
                            taskList.add(taskShow);
                        } else {
                            TaskShow taskShow = new TaskShow();
                            taskShow.setType(3);
                            taskList.add(taskShow);
                            TaskShow taskShow1 = new TaskShow();
                            taskShow1.setType(4);
                            taskList.add(taskShow1);
                        }
                    }
                    myAdapter.notifyDataSetChanged();//刷新列表数据
                } else {
                    Log.i("Bmob", "查找失败");
                }
            }
        });

    }

    public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements View.OnClickListener {

        //提供set方法供Activity或Fragment调用
        public void setRecyclerItemClickListener(OnRecyclerItemClickListener listener) {
            monItemClickListener = listener;
        }

        @NonNull
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            if (viewType == 1) {
                View view = LayoutInflater.from(getActivity()).inflate(R.layout.item_list_one, parent, false);
                return new MyViewHolderOne(view);
            } else if (viewType == 2) {
                View view = LayoutInflater.from(getActivity()).inflate(R.layout.item_list_two, parent, false);
                return new MyViewHolderTwo(view);
            } else if (viewType == 3) {
                View view = LayoutInflater.from(getActivity()).inflate(R.layout.item_home_banner, parent, false);
                return new MyViewHolder(view);
            } else if (viewType == 4) {
                View view = LayoutInflater.from(getActivity()).inflate(R.layout.item_list_three, parent, false);
                return new MyViewHolderThree(view);
            } else {
                View view = LayoutInflater.from(getActivity()).inflate(R.layout.item_list_four, parent, false);
                return new MyViewHolderFour(view);
            }
        }
        @SuppressLint("ResourceAsColor")
        @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
        @Override
        public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
            int type = getItemViewType(position);
            if (type == 1) {
                MyViewHolderOne holder1 = (MyViewHolderOne) holder;
                holder1.titleView.setText(taskList.get(position).getTitle());
                holder1.labelView.setText(taskList.get(position).getLabel());
                holder1.amountView.setText(taskList.get(position).getAmount() + "元");
                holder1.taskId.setText(taskList.get(position).getTaskId());
                holder1.time.setText(taskList.get(position).getTime());
                holder1.finishTime.setText(taskList.get(position).getTaskTime() + "内完成");
                Glide.with(getActivity()).
                        load(taskList.get(position).getHeadimg())
                        .into(holder1.headimgView);
            } else if (type == 2) {
                MyViewHolderTwo holder2 = (MyViewHolderTwo) holder;
                holder2.taskId.setText(taskList.get(position).getTaskId());
                holder2.titleView.setText(taskList.get(position).getTitle());
                holder2.labelView.setText(taskList.get(position).getLabel());
                holder2.amountView.setText(taskList.get(position).getAmount() + "元");
                Glide.with(getActivity()).
                        load(taskList.get(position).getHeadimg())
                        .into(holder2.headimgView);
                holder2.title1View.setText(taskList.get(position).getTitle1());
                holder2.label1View.setText(taskList.get(position).getLabel1());
                holder2.amount1View.setText(taskList.get(position).getAmount1() + "元");
                holder2.taskId1.setText(taskList.get(position).getTaskId1());
                Glide.with(getActivity()).
                        load(taskList.get(position).getHeadimg1())
                        .into(holder2.headimg1View);
            } else if (type == 3) {
                //initBannerView();
                MyViewHolder holder3 = (MyViewHolder) holder;
//                holder3.bannerBg.setBackgroundColor(Color.parseColor("#E84830"));
//                setStatusBarColor(getActivity(), Color.parseColor("#E84830"));
//                viewBg.setBackgroundColor(Color.parseColor("#E84830"));
                bannerList.clear();
                bannerList.add("http://photogz.photo.store.qq.com/psc?/V13FgbWj3x2RyI/05RlWl8gsTOH*Z17MtCBzL38dQIMpiYdn8ShmfcTlrB7hszajovOcG6bK.MZRKCVpJz6MkkTubTObfR8SmxhrA!!/m&bo=dgWNAXYFjQERADc!&rf=mood_app");
                bannerList.add("http://photogz.photo.store.qq.com/psc?/V13FgbWj3x2RyI/05RlWl8gsTOH*Z17MtCBzPPKeusL5Yh5Me*b9D9zIEzfwj449tGqot8n*P5fppSq.xNrIOEi6SCRnjWPBvSq9A!!/m&bo=eAWOAXgFjgERADc!&rf=mood_app");
                bannerList.add("http://photogz.photo.store.qq.com/psc?/V13FgbWj3x2RyI/05RlWl8gsTOH*Z17MtCBzOW.ae376BfI9lGqS3HjDUb5oNlSXGoMgFfKuN0T.uuIfh9AR75LBj68IZwrB1zHJQ!!/m&bo=IwPZACMD2QARADc!&rf=mood_app");
                bannerList.add("http://photogz.photo.store.qq.com/psc?/V13FgbWj3x2RyI/05RlWl8gsTOH*Z17MtCBzLojxvQGIuIDakj72A2tcGXUTs6ac0pqlFaMItaWj0tQTUVqg6jXn5TioYk6Lbf6YA!!/m&bo=zgWiAc4FogERADc!");
                count = bannerList.size();
                colorList.clear();
                for (int i = 0; i <= count + 1; i++) {
                    ColorInfo info = new ColorInfo();
                    if (i == 0) {
                        info.setImgUrl(bannerList.get(count - 1));
                    } else if (i == count + 1) {
                        info.setImgUrl(bannerList.get(0));
                    } else {
                        info.setImgUrl(bannerList.get(i - 1));
                    }
                    colorList.add(info);
                }
                imageLoader = new BannerImageLoader(colorList);
                banner.setImageLoader((ImageLoaderInterface) imageLoader);
                //设置图片集合
                banner.setImages(bannerList);
                //设置banner动画效果
                banner.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                    @Override
                    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                        if (positionOffset > 1) {//会出现极个别大于1的数据
                            return;
                        }
                        //修正position，解决两头颜色错乱，来自Banner控件源码
                        if (position == 0) {
                            position = count;
                        }
                        if (position > count) {
                            position = 1;
                        }
                        int pos = (position + 1) % count;//很关键

                        int vibrantColor = ColorUtils.blendARGB(imageLoader.getVibrantColor(pos), imageLoader.getVibrantColor(pos + 1), positionOffset);
                        holder3.bannerBg.setBackgroundColor(vibrantColor);
                        viewBg.setBackgroundColor(vibrantColor);

                        setStatusBarColor(getActivity(), vibrantColor);
                    }

                    @Override
                    public void onPageSelected(final int position) {
                        if (isInit) {// 第一次,延时加载才能拿到颜色
                            isInit = false;
                            new Handler().postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    int vibrantColor = imageLoader.getVibrantColor(1);
                                    holder3.bannerBg.setBackgroundColor(vibrantColor);
                                    setStatusBarColor(getActivity(), vibrantColor);
                                }
                            }, 200);

                        }
                    }

                    @Override
                    public void onPageScrollStateChanged(int i) {

                    }
                });
                 banner.setBannerAnimation(Transformer.ZoomOutSlide);
                 //ZoomOut 放大推出
                //ZoomOutSlide 缩小推出
                //ScaleInOut 折叠
                //Stack 滑动
                //Tablet 向里折叠
                //Accordion 从左到右压过去
                //设置轮播时间
               banner.setDelayTime(3000);
                banner.setOnBannerListener(new OnBannerListener() {
                    @Override
                    public void OnBannerClick(int position) {

                    }
                });
                //banner设置方法全部调用完毕时最后调用
                banner.start();
            } else if (type == 4) {
                MyViewHolderThree holder4=(MyViewHolderThree) holder;
                RequestOptions options = RequestOptions.bitmapTransform(new RoundedCorners(30));//图片圆角为30
                Glide.with(getContext()).load("http://a1.qpic.cn/psc?/V54ETsN62Rdw772wFsNq0jEkXI4LU2rF/05RlWl8gsTOH*Z17MtCBzOvr3G8UUkGNXucWAWeLcOOf7ET3suDl.v3QUT363XC*YI7eefSyllNH2a47x3tDtA!!/m&ek=1&kp=1&pt=0&bo=kAHIAJAByAARADc!&tl=1&tm=1622390400&sce=0-12-12&rf=0-18").apply(options).into(holder4.img1);
                Glide.with(getContext()).load("http://a1.qpic.cn/psc?/V54ETsN62Rdw772wFsNq0jEkXI4LU2rF/05RlWl8gsTOH*Z17MtCBzDIzxAjtwU1kz4RIhinwRHwgLJ2gf2cLhZcsmPz2MvKuq*ThqibSA5uMlxYPzpgt0w!!/m&ek=1&kp=1&pt=0&bo=kQHIAJEByAARADc!&tl=1&tm=1622390400&sce=0-12-12&rf=0-18").apply(options).into(holder4.img2);
                Glide.with(getContext()).load("http://a1.qpic.cn/psc?/V54ETsN62Rdw772wFsNq0jEkXI4LU2rF/05RlWl8gsTOH*Z17MtCBzOlP4VcbA86D1Kku*kbcYmUJrbHktDLFVKJl2ENZGdeCBi2QlPAmB5D46BJ*tlNRdg!!/m&ek=1&kp=1&pt=0&bo=kAHIAJAByAARADc!&tl=1&tm=1622390400&sce=0-12-12&rf=0-18").apply(options).into(holder4.img3);

            } else {

            }
        }

        @Override
        public int getItemCount() {
            return taskList.size();
        }

        @Override
        public int getItemViewType(int position) {
            return taskList.get(position).getType();
        }

        @Override
        public void onClick(View v) {

        }
    }

    public class MyViewHolderOne extends RecyclerView.ViewHolder {
        ImageView headimgView;
        TextView titleView, labelView, amountView, taskId, time, finishTime;

        public MyViewHolderOne(@NonNull View itemView) {
            super(itemView);
            taskId = itemView.findViewById(R.id.textView98);
            headimgView = itemView.findViewById(R.id.circleImageView);
            titleView = itemView.findViewById(R.id.textView9);
            labelView = itemView.findViewById(R.id.textView10);
            amountView = itemView.findViewById(R.id.textView39);
            time = itemView.findViewById(R.id.textView88);
            finishTime = itemView.findViewById(R.id.textView74);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (monItemClickListener != null) {
                        intentTaskId = taskId.getText().toString();
                        monItemClickListener.onItemClick(getAdapterPosition(), taskList);
                    }
                }
            });
        }
    }

    public class MyViewHolderTwo extends RecyclerView.ViewHolder {
        ImageView headimgView, headimg1View;
        TextView titleView, labelView, amountView, title1View, label1View, amount1View, taskId, taskId1;
        ConstraintLayout constraintLayout1, constraintLayout2;

        public MyViewHolderTwo(@NonNull View itemView) {
            super(itemView);
            taskId = itemView.findViewById(R.id.textView99);
            headimgView = itemView.findViewById(R.id.circleImageView);
            titleView = itemView.findViewById(R.id.textView9);
            labelView = itemView.findViewById(R.id.textView10);
            amountView = itemView.findViewById(R.id.textView39);
            headimg1View = itemView.findViewById(R.id.circleImageView2);
            title1View = itemView.findViewById(R.id.textView11);
            label1View = itemView.findViewById(R.id.textView19);
            amount1View = itemView.findViewById(R.id.textView40);
            taskId1 = itemView.findViewById(R.id.textView84);
            constraintLayout1 = itemView.findViewById(R.id.constraintlayout1);
            constraintLayout2 = itemView.findViewById(R.id.constraintlayout2);
            constraintLayout1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (monItemClickListener != null) {
                        Log.i("21", "*");
                        intentTaskId = taskId.getText().toString();
                        monItemClickListener.onItemClick(getAdapterPosition(), taskList);
                    }
                }
            });
            constraintLayout2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (monItemClickListener != null) {
                        Log.i("21", "**");
                        intentTaskId = taskId1.getText().toString();
                        monItemClickListener.onItemClick(getAdapterPosition(), taskList);
                    }
                }
            });
        }
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView bannerBg;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            banner = itemView.findViewById(R.id.banner2);
            bannerBg=itemView.findViewById(R.id.iv_banner_head_bg);
//            mLoopPager = itemView.findViewById(R.id.looper_pager);
//            pointContainer = itemView.findViewById(R.id.points_layout);
//            for (int i = 0; i < sColors.size(); ++i) {
//                View point = new View(getContext());
//                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(40, 40);
//                point.setBackground(getResources().getDrawable(R.drawable.shape_point_normal));
//                layoutParams.leftMargin = 40;
//                point.setLayoutParams(layoutParams);
//                pointContainer.addView(point);
//                itemView.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        if (monItemClickListener != null) {
//                            Log.i("21", "***");
//                            monItemClickListener.onItemClick(getAdapterPosition(), taskList);
//                        }
//                    }
//                });
//            }
        }
    }

    public class MyViewHolderThree extends RecyclerView.ViewHolder {
        ImageView img1,img2,img3;
        public MyViewHolderThree(@NonNull View itemView) {
            super(itemView);
            img1=itemView.findViewById(R.id.imageView61);
            img2=itemView.findViewById(R.id.imageView62);
            img3=itemView.findViewById(R.id.imageView63);
        }
    }

    public class MyViewHolderFour extends RecyclerView.ViewHolder {
        public MyViewHolderFour(@NonNull View itemView) {
            super(itemView);
        }
    }
    public static void setStatusBarColor(Activity activity, int color) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = activity.getWindow();
            //状态栏改变颜色。
            window.setStatusBarColor(color);
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        banner.stopAutoPlay();
    }
}